#include <iostream>
#include <math.h>

using namespace std;


void biweekMortgage() {
	double principal, rate;
	int period, month, biwk;
	double monPay, biwkPay, monInt, biwkInt, avgMonInt, avgBiwkInt;
	double monRate, biwkRate;
	
	// collect inputs from user
	cout<<"Enter the Principal Loan Balance here: ";
	cin>>principal;
	cout<<"Enter the Annual Interest Rate here: ";
	cin>>rate;
	cout<<"Enter the Amorization Length here: ";
	cin>>period;
	month = period * 12;
	monRate = rate / 12;
	
	monPay = principal * monRate * pow((1+monRate), month)/(pow((1+monRate), month) - 1) ;
	monInt = monPay * month - principal;
	avgMonInt = monInt / month;
	
	// display monthly output 
	cout << "Monthly payment is: $" << monPay << endl;
	cout << "Total interest is: $" << monInt << endl;
	cout << "Average interest each month is: $" << avgMonInt<<endl;

	biwkPay = monPay / 2;
    biwkRate = rate/26;
    double upper = log(biwkPay/(biwkPay - principal*biwkRate));
    double bottom = log(1+biwkRate);
    biwk = upper/bottom;
    biwkInt = biwkPay*biwk - principal;
    avgBiwkInt = biwkInt / biwk;
    
	// display biweekly output 
    
	cout << "\nbiweekly payment is: $" << biwkPay <<endl;
	cout << "Total interest is: $" << biwkInt << endl;
    cout << "Average interest for every two weeks is: $" << avgBiwkInt << endl;
	
	system("pause");
}